#!/bin/sh
function jednotlive {
    files=("/home/milos/Stažené/instance3/040_070.wcnf" "/home/milos/Stažené/instance3/080_200.wcnf" "/home/milos/Stažené/instance3/100_400.wcnf" "/home/milos/Stažené/instance3/uf20-010.wcnf" "/home/milos/Stažené/instance3/uf20-011.wcnf")
    echo "pripad,prumer,hits"
    for i in ${files[@]}; do
      for j in 1 2 3 4 5 6; do
        for k in 1 2 3 4 5;do
            deviationSum=0
            hitSum=0
            IFS=$'\n'
            for line in `cat "${i}.sol.sat_annealing.${j}.initTemp${k}"`; do
                hit=`echo $line | cut -d" " -f2`
                deviation=`echo $line | cut -d" " -f3 | tr ',' '.'`
                deviationSum=`echo "$deviationSum + $deviation" | bc`
                if [ $hit != "0" ]; then
                    hitSum=`expr $hitSum + 1`
                fi
            done
            IFS=" "
            lineCount=`cat "${i}.sol.sat_annealing.${j}.initTemp${k}" | wc -l`
            average=`echo "scale=4;$deviationSum/$lineCount" | bc`

            echo "$i - cost:$j - temp:$k,$average,$hitSum"
        done
      done
    done
}

function byCombination {
    files=("/home/milos/Stažené/instance3/040_070.wcnf" "/home/milos/Stažené/instance3/080_200.wcnf" "/home/milos/Stažené/instance3/100_400.wcnf" "/home/milos/Stažené/instance3/uf20-010.wcnf" "/home/milos/Stažené/instance3/uf20-011.wcnf")
    echo "pripad,prumer,hits"

    for j in 1 2 3 4 5 6; do
      for k in 1 2 3 4 5;do
        averageSum=0
        hitSumSum=0
        for i in ${files[@]}; do
            deviationSum=0
            hitSum=0
            IFS=$'\n'
            for line in `cat "${i}.sol.sat_annealing.${j}.initTemp${k}"`; do
                hit=`echo $line | cut -d" " -f2`
                deviation=`echo $line | cut -d" " -f3 | tr ',' '.'`
                deviationSum=`echo "$deviationSum + $deviation" | bc`
                if [ $hit != "0" ]; then
                    hitSum=`expr $hitSum + 1`
                fi
            done
            IFS=" "
            lineCount=`cat "${i}.sol.sat_annealing.${j}.initTemp${k}" | wc -l`
            average=`echo "scale=4;$deviationSum/$lineCount" | bc`
            averageSum=`echo "$averageSum + $average" | bc`
            hitSumSum=`echo "$hitSumSum + $hitSum" | bc`
        done
        combinationAverage=`echo "scale=4;$averageSum / 5" | bc`
        hitsAverage=`echo "$hitSumSum / 5" | bc`
        echo "combination - cost:$j - temp:$k,$combinationAverage,$hitsAverage"
      done
    done
}

function hitCountOfInstances {
    files=`ls ../*.sat_annealing`
    hitSum=0
    for line in $files; do
        hit=`cat $line | cut -d" " -f2`
        if [ $hit != "0" ]; then
            hitSum=`expr $hitSum + 1`
        fi
    done

    echo $hitSum
}

function deviationOfInstances {
    files=`ls ../*.sat_annealing`
    instances=200
    deviationSum=0
    for line in $files; do
        deviation=`cat $line | cut -d" " -f3 | tr ',' '.'`
        deviationSum=`echo "$deviationSum + $deviation" | bc`
    done
    average=`echo "scale=4;$deviationSum/$instances" | bc`

    echo $average
}
#jednotlive > veliciny.csv

#byCombination > byCombination.csv
#hitCountOfInstances
deviationOfInstances